package vn.keho.module.dompeto.model;

import com.google.gson.annotations.SerializedName;

import org.json.JSONArray;
import org.json.JSONObject;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by KeHo on 2/4/15.
 */
public class WalletProfile {

    @SerializedName("pagesize")
    private int pagesize;
    @SerializedName("channelperpagesize")
    private int channelperpagesize;
    @SerializedName("channelsize")
    private int channelsize;
    @SerializedName("themeid")
    private int themeid;
    @SerializedName("themebackground")
    private Integer themebackground;
    @SerializedName("themeslot")
    private Integer themeslot;
    @SerializedName("pages")
    private List<PageModel> pages;

    public WalletProfile() {
    }

    public WalletProfile(JSONObject jsonObject) {
        try {
            this.pagesize = jsonObject.getInt("pagesize");
            this.channelperpagesize = jsonObject.getInt("channelperpagesize");
            this.channelsize = jsonObject.getInt("channelsize");
            this.themeid = jsonObject.getInt("themeid");
            this.themebackground = jsonObject.getInt("themebackground");
            this.themeslot = jsonObject.getInt("themeslot");

            this.pages = new ArrayList<PageModel>();
            JSONArray jsonArray = jsonObject.getJSONArray("pages");
            for(int i = 0; i < jsonArray.length(); i++) {
                JSONObject jsPageObject = jsonArray.getJSONObject(i);
                PageModel pageModel = new PageModel(jsPageObject);
                this.pages.add(pageModel);
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    public JSONObject toJSON() {
        JSONObject jsonObject = new JSONObject();
        try {
            jsonObject.put("pagesize", pagesize);
            jsonObject.put("channelperpagesize", channelperpagesize);
            jsonObject.put("channelsize", channelsize);
            jsonObject.put("themeid", themeid);
            jsonObject.put("themebackground", themebackground);
            jsonObject.put("themeslot", themeslot);

            JSONArray pageArray = new JSONArray();
            for(PageModel pageModel : pages) {
                pageArray.put(pageModel.toJSON());
            }
            jsonObject.put("pages", pageArray);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return jsonObject;
    }

    public int getPagesize() {
        return pagesize;
    }

    public void setPagesize(int pagesize) {
        this.pagesize = pagesize;
    }

    public int getChannelperpagesize() {
        return channelperpagesize;
    }

    public void setChannelperpagesize(int channelperpagesize) {
        this.channelperpagesize = channelperpagesize;
    }

    public int getChannelsize() {
        return channelsize;
    }

    public void setChannelsize(int channelsize) {
        this.channelsize = channelsize;
    }

    public int getThemeid() {
        return themeid;
    }

    public void setThemeid(int themeid) {
        this.themeid = themeid;
    }

    public Integer getThemebackground() {
        return themebackground;
    }

    public void setThemebackground(Integer themebackground) {
        this.themebackground = themebackground;
    }

    public Integer getThemeslot() {
        return themeslot;
    }

    public void setThemeslot(Integer themeslot) {
        this.themeslot = themeslot;
    }

    public List<PageModel> getPages() {
        return pages;
    }

    public void setPages(List<PageModel> pages) {
        this.pages = pages;
    }
}
